

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>

#include "common/utils.hpp"

void dfs(std::vector<int>& result, NTreeNode* node) {
    if (node == nullptr) return;

    int len = node->nodes.size();
    for (int i = 0; i < len; i++) {
        dfs(result, node->nodes[i]);
    }
    result.push_back(node->val);
}

std::vector<int> postorder(NTreeNode* root) {
    std::vector<int> ret;
    dfs(ret, root);
    return ret;
}

extern NTreeNode* commonNRoot;

int main() {
    std::vector<int> res = postorder(commonNRoot);
    printVector(res);
}